package 面向对象.实验六;

import java.util.*;

/**
 * @projectName: JAVA编程
 * @package: 面向对象.实验六
 * @className: test2
 * @author: hhy帅
 * @description: TODO
 * @date: 2021/11/7 22:02
 */
public class test2 {
    public static void main(String[] args) {
        Book book1 = new Book("1","aa","aaa");
        Book book2 = new Book("2","bb","bbb");
        Book book3 = new Book("3","cc","ccc");
        myLinkedList(book1,book2,book3);
        myArrayList(book1,book2,book3);
        myHashSet(book1,book2,book3);
        myHashMap(book1,book2,book3);
    }
    public static void myLinkedList(Book book1,Book book2,Book book3){
        LinkedList<Book> linkedList = new LinkedList<Book>();
        linkedList.add(book1);
        linkedList.add(book2);
        linkedList.add(book3);
        for (Book book : linkedList){
            System.out.println(book);
        }
    }
    public static void myArrayList(Book book1,Book book2,Book book3){
        ArrayList<Book> arrayList = new ArrayList<>();
        arrayList.add(book1);
        arrayList.add(book2);
        arrayList.add(book3);
        for (Book book : arrayList){
            System.out.println(book);
        }
    }
    public static void myHashSet(Book book1,Book book2,Book book3){
        HashSet<Book> hashSet = new HashSet<>();
        hashSet.add(book1);
        hashSet.add(book2);
        hashSet.add(book3);
        for (Book book : hashSet){
            System.out.println(book);
        }

    }
    public static void myHashMap(Book book1,Book book2,Book book3){
        HashMap<Integer, Book> hashMap = new HashMap<>();
        hashMap.put(0,book1);
        hashMap.put(1,book2);
        hashMap.put(2,book3);
        Iterator<Map.Entry<Integer,Book>> entries = hashMap.entrySet().iterator();
        while (entries.hasNext()){
            Map.Entry<Integer,Book> entry=entries.next();
            System.out.println("KEY=" + entry.getKey() + "VALUES=" + entry.getValue());
        }
    }
}
